﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Edge.Business.Entities;
using Edge.Common;
using Edge.Common.Services;
using Edge.Common.Utils;
using Iesi.Collections.Generic;
using Shop.Business.Domain.Catalog.Parameter;
using Shop.Business.Domain.Customers;
using Shop.Business.Domain.Pricing;

namespace Shop.Business.Domain.Catalog
{
    /// <summary>
    /// Users object for NHibernate mapped table 'product_group'.
    /// </summary>
    [Serializable]
    public class ProductGroup : EntityWithStat<int>
    {

        protected string name;
        protected string description;
        protected string brandName;
        protected Brand brand;
        protected Category category;
        protected int margin;
        protected int qty;
        protected int relevance;
        protected bool visible = true;
        protected GroupStatus? status;
        protected ISet<Product> products;
        protected ISet<SizeValue> sizeValues;
        protected ISet<PriceItem> priceItems;
        protected decimal maxPrice;
        protected decimal minPrice;

        public virtual decimal MaxPrice
        {
            get { return maxPrice; }
            set { maxPrice = value; }
        }

        public virtual decimal MinPrice
        {
            get { return minPrice; }
            set { minPrice = value; }
        }

        public virtual string Price
        {
            get
            {
                if (maxPrice == minPrice)
                    return maxPrice.ToString("C");
                return minPrice.ToString("F") + " - " + maxPrice.ToString("C");
            }
        }

        public virtual string Name
        {
            get { return name; }
            set { name = value; }
        }

        public virtual string BrandName
        {
            get { return brandName; }
            set { brandName = value; }
        }

        public virtual string Description
        {
            get { return description; }
            set { description = value; }
        }

        public virtual Brand Brand
        {
            get { return brand; }
            set { brand = value; }
        }

        public virtual Category Category
        {
            get { return category; }
            set { category = value; }
        }

        public virtual int Margin
        {
            get { return margin; }
            set { margin = value; }
        }

        public virtual bool Visible
        {
            get { return visible; }
            set { visible = value; }
        }

        public virtual GroupStatus? Status
        {
            get { return status; }
            set { status = value; }
        }

        public virtual ISet<Product> Products
        {
            get
            {
                return products;
            }
            set
            {
                products = value;
            }
        }

        public virtual int Relevance
        {
            get { return relevance; }
            set { relevance = value; }
        }

        public virtual int Qty
        {
            get { return qty; }
            set { qty = value; }
        }

        public virtual ISet<PriceItem> PriceItems
        {
            get { return priceItems; }
            set { priceItems = value; }
        }

        public virtual ICollection<Parameter.Parameter> Parameters
        {

            get { return Locator.GetService<IParameterManager>().GetGroupParameters(Id); }
        }

        public virtual ISet<SizeValue> SizeValues
        {

            get { return sizeValues; }
            set { sizeValues = value; }
        }
    }

    public enum GroupStatus
    {
        [Description("Новинка")]
        New = 1,
        [Description("Хит продаж")]
        Hit = 2,

    }
    public class SizeValue : BaseEntity<int>
    {

        protected int qty;
        protected string value;
        protected ProductGroup group;

        public virtual string Value
        {
            get { return value; }
            set { this.value = value; }
        }

        public virtual int Qty
        {
            get { return qty; }
            set { qty = value; }
        }

        public virtual ProductGroup Group
        {
            get { return group; }
            set { group = value; }
        }
    }
}